<?php

namespace App\Models\Operate;

use Illuminate\Database\Eloquent\Model;

class Config extends Model
{
    protected $table = 'configs';

    protected $fillable = [
        'title','content','type','img','descrition','config_type'
    ];

    protected $type = [
        1 => '房主需知',
        2 => '开房流程',
        3 => '房主收入费用',
        4 => '开奖规格',
        5 => '奖品回购需知',
        6 => '回购协议',
        7 => '隐私声明',
        8 => '风险需知',
        9 => '创建规则',
        10 => '发货须知',
        11 => '出售须知',
        12 => '收益规则',
        13 => '用户协议',
        14 => '代理须知',
    ];

    public function getTypeAttribute($value)
    {
        if(request()->route('appsetting'))
        {
            return $this->attributes['type'] =  $value;
        }elseif (request()->getRequestUri() == '/api/v1/config/primary'){
            return $this->attributes['type'] =  $value;
        }else{

            return $this->attributes['type'] =  $this->type[$value] ?? '--';
        }
    }

    public function setTypeAttribute($value)
    {
        if(is_array($value)){
            return $this->attributes['type'] =  array_merge(array_filter($value))[0];
        }else {
            return $this->attributes['type'] = $value;
        }


    }
}
